package acm.蓝桥23;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * 把所有球
 */
public class A_有嫌疑的球 {
	static Set<Integer> legal = new HashSet<>(); // 合法的球
	static Set<Integer> issue = new HashSet<>(); // 争议球
	static int n, m;

	/**
	 * 碰到等于号：放入合法球中 碰到小于号，放到争议球中，如果最后争议球是空集，那么结果为n-合法球
	 */
	public static void main(String[] args) {
		Reader sc = new Reader();
		n = sc.nextInt();
		m = sc.nextInt();
		while (m-- > 0) {
			Set<Integer> left = new HashSet<>();
			Set<Integer> right = new HashSet<>();
			int cnt = sc.nextInt();
			for (int i = 0; i < cnt; i++) {
				left.add(sc.nextInt());
			}
			for (int i = 0; i < cnt; i++) {
				right.add(sc.nextInt());
			}
			String op = sc.next();
			switch (op) {
			case "=":
				legal.addAll(left);
				legal.addAll(right);
				break;
			case ">":
				legal.addAll(left);
				if(issue.size()==0) {
					right.forEach(o->{
						if(!legal.contains(o)) {
							issue.add(o);
						}
					});
				}else {
					issue = right.stream().filter(issue::contains).collect(Collectors.toSet());
				}
				break;
			case "<":
				legal.addAll(right);
				if(issue.size()==0) {
					left.forEach(o->{
						if(!legal.contains(o)) {
							issue.add(o);
						}
					});
				}else {
					issue = left.stream().filter(issue::contains).collect(Collectors.toSet());
				}
				break;
			}
			if(issue.size()==1) {
				break;
			}
		}
		if(issue.size()==0) {
			System.out.println(n-legal.size());
		}else {
			int total=issue.size();
			int remove=(int) issue.stream().filter(legal::contains).count();
			System.out.println(total-remove);
		}
	}
	 static class Reader {
		    private PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		    private StringTokenizer tokenizer = new StringTokenizer("");

		    private String innerNextLine() {
		        try {
		            return reader.readLine();
		        } catch (IOException ex) {
		            return null;
		        }
		    }

		    public boolean hasNext() {
		        while (!tokenizer.hasMoreTokens()) {    //内存中没有
		            String nextLine = innerNextLine();
		            if (nextLine == null) {     //且没有下一行
		                return false;
		            }
		            tokenizer = new StringTokenizer(nextLine);  //读入一行
		        }
		        return true;
		    }

		    public String nextLine() {
		        tokenizer = new StringTokenizer("");    //清空内存中的字符
		        return innerNextLine();
		    }

		    public void clear() {
		        tokenizer = new StringTokenizer("");
		    }

		    public String next() {
		        hasNext();
		        return tokenizer.nextToken();
		    }

		    public int nextInt() {
		        return Integer.parseInt(next());
		    }

		    public long nextLong() {
		        return Long.parseLong(next());
		    }

		    public double nextDouble() {
		        return Double.parseDouble(next());
		    }

		    //    public BigInteger nextBigInt() {
//		        return new BigInteger(next());
//		    }

		}

}
